<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@page contentType="text/xml"%>
<%@page pageEncoding="UTF-8"%>
<%
        response.setHeader("Cache-Control", "no-cache"); //HTTP 1.1
        response.setHeader("Pragma", "no-cache"); //HTTP 1.0
        response.setDateHeader("Expires", 0); //prevent caching at the proxy server
%>
<sql:query var="query" dataSource="jdbc/dbo_MicrosoftSQLServer">
    select  m.id_modulo,m.desc_modulo, 
    c.id_componente,desc_componente,
    codigo_componente, 
    r.*, s.desc_sala, u.desc_unidade
    from Componentes c
    inner join grades g on g.id_componente=c.id_componente
    inner join modulos m on m.id_modulo=g.id_modulo
    inner join reservas r on r.id_modulo=m.id_modulo and r.id_componente=g.id_componente
    left join salas s on r.id_sala=s.id_sala
    left join unidades u on u.id_unidade=s.id_unidade
    where r.id_turma=?
    order by ordem, ordem_componente
    <sql:param value="${param.id_turma}"/>
</sql:query>

<rows>
    <c:choose>
        <c:when test="${empty param.page}">
            <page>1</page>
        </c:when>
        <c:otherwise>
            <page>${param.page}</page>
        </c:otherwise>
    </c:choose>
    <total><fmt:formatNumber value="${query.rowCount/10}" pattern="######"/></total>
    <records>${query.rowCount} </records>
    <c:forEach var="row" items="${query.rows}">
        <row id ="${row.id_reserva}">
            <cell>${row.ordem}</cell>
            <cell>${fn:trim(row.desc_modulo)}</cell>
            <cell>${fn:trim(row.desc_componente)}</cell>
            <cell>${row.carga_horaria}</cell>
            <cell><fmt:formatDate pattern="dd/MM/yyyy" value="${row.data_inicio}"/></cell>
            <cell><fmt:formatDate pattern="dd/MM/yyyy" value="${row.data_fim}"/></cell>
            <cell>${fn:trim(row.desc_sala)}-${fn:trim(row.desc_unidade)}</cell>
            <cell>${row.subturma}</cell>
            <cell></cell>
            <cell>${row.id_regra_horarios}</cell>
        </row>
    </c:forEach>
</rows>